const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// const entry = require('./webpack/entry');
// const extra = require('./webpack/extra');
// const entrys = entry(path.resolve(__dirname, './vue'));
//const VueLoaderPlugin = require('vue-loader/lib/plugin');
// console.log('entrys===>', entrys);
module.exports = {
    entry: __dirname + '/src/index.js',
    output: {
        path: __dirname + '/dist',
        filename: 'main.js'
    },
    module:{
        rules:[{
            test:/\.js?$/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                      "latest",
                      "stage-0",
                    ],
                }
            },
            exclude: /node_modules/,

        },
        {
            test: /\.vue$/,
            use: ['vue-loader'],
            exclude: /node_module/,
        },
        {
            test:/\.css$/,
            use: ['style-loader', 'css-loader'],
        },
        {
            test:/\.less$/,
            use:[
                "style-loader",
                {
                    loader:'css-loader',
                    options:{url: false, sourceMap: true},
                },
                {
                    loader:'less-loader',
                }
            ],
        },
        {
            test: /\.(png|jpg|jpeg)$/,
            loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]',
            options: {
                publicPath: '/'
            }
        }, {
            test: /\.(woff|woff2|eot|ttf|otf)$/,
            loader: 'file-loader',
            options: {
                publicPath: '/'
            }
        }]
    },
    resolve: {
        // 设置别名
        alias: {
            '@': path.join(__dirname, '/src'),
        }
    },
    devtool:"eval-source-map",
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        port: 8099,
        host: '0.0.0.0',
        proxy: {
            '/api': {
                target: 'http://127.0.0.1:7001',
                changeOrigin: true,
                pathRewrite: {
                    '^/api': '',
                }
            }
        }
    },
    plugins: [
        // new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title: '短视频平台',
            meta: {
                keywords: '短视频',
                description: '动画'
            },
            inject: true,
            template: path.join(__dirname, '/template.html'),
            filename:'index.html',
            minify: {
                collapseWhitespace: true,
                preserveLineBreaks: true
            }
        })
    ]
}
